package com.bootdo.shopweb.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bootdo.common.config.Constant;
import com.bootdo.common.domain.Tree;
import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import com.bootdo.oa.domain.NotifyDO;
import com.bootdo.oa.service.NotifyService;
import com.bootdo.shop.domain.CategoryDO;
import com.bootdo.shop.domain.ProductDO;
import com.bootdo.shop.service.CategoryService;
import com.bootdo.shop.service.ProductService;
import com.bootdo.system.domain.MenuDO;
/**
 * 商城首页
 * @author Administrator
 *
 */
@RequestMapping("/shop")
@Controller
public class ShopController {

	
	@Autowired
	private NotifyService notifyService;
	@Autowired
	private CategoryService categoryService;
	@Autowired 
	private ProductService productService;
	@GetMapping()
	String shop(Model model) {
		
		List<Tree<CategoryDO>> menus = categoryService.listMenuTree();
		
		
		//List<ProductDO> hotProductList=	productService.hotProductList();
		//首页分类以及产品展示
		Map<String, Object> params =new HashMap<String, Object>();
		 params.put("showInHot", 1);
		List<CategoryDO> listall = categoryService.list(params);
		
		for (CategoryDO categoryDO : listall) {
			
			List<CategoryDO> blist = categoryService.getCategoryBrotherList(categoryDO.getCategoryId());
			Map<String, Object> map =new HashMap<String, Object>();
			map.put("categoryId", categoryDO.getCategoryId());
			List<ProductDO> plist =productService.list(map);
			
			categoryDO.setClist(blist);
			categoryDO.setProductList(plist);
			
		}
		//首页分类以及产品展示end

		model.addAttribute("menus", menus);
		model.addAttribute("hotProductList", listall);
		return "shop/index/main";
	}
	//商城首页公告列表查询
	@ResponseBody
	@GetMapping("/index/noticelist")
	public Object getnotice() {
		
		List<NotifyDO> list =notifyService.list(null);
		
		return list;
	}
	/**
	 * 首页三级分类查询 暂停用
	 * @return
	 */
	@ResponseBody
	@GetMapping("/index/getProductType")
	public Object getProductType() {
		
		List<Tree<CategoryDO>> menus = categoryService.listMenuTree();
		
		return menus;
	}
	/**
	 * 获取首页热门展示的产品
	 * @return
	 */
	@ResponseBody
	@GetMapping("/index/getHotProductList")
	public Object getHotProductList() {
		
		
		List<ProductDO> hotProductList=	productService.hotProductList();
		
		
		return hotProductList;
		
		
	}
	
}
